/**
 * 
 */
package com.bagtrack.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.bagtrack.model.SearchQuery;
import com.bagtrack.model.User;
import com.bagtrack.service.IJobService;
import com.bagtrack.service.IUserService;


/**
 * Controller Class for handling requests for application statistics.
 * @author Brian Boyle
 * Nov 18, 2011
 */
@Controller
public class StatsController {

    @Autowired
    private IUserService userService;
    @Autowired
    private IJobService jobService;

    public void setUserService(IUserService userService) {
        this.userService = userService;
    }

    public void setJobService(IJobService jobService) {
        this.jobService = jobService;
    }

    @RequestMapping(value = "/stats")
    public ModelAndView loadPageDefaults(Model model) {
        List<User> users = userService.findAllUsers();
        model.addAttribute("users", users);
        SearchQuery query = new SearchQuery();
        model.addAttribute("searchQuery", query);
        model.addAttribute("dataXML", "Some XML");
        return new ModelAndView("stats");
    }

    @RequestMapping(value = "/searchJobs", method = RequestMethod.POST)
    public ModelAndView searchJobs(@ModelAttribute("searchQuery") SearchQuery query, Model model) {

        //Map<String, String> mapResults = jobService.searchJobs(query);

        //CONSTRUCT CHART XML WITH MAPRESULTS

        model.addAttribute("dataXML", "Some XML");
        model.addAttribute("searchQuery", query);
        return new ModelAndView("stats");
    }
}
